package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.entity.GsOrder;
import edu.scau.mis.cloth.dao.GsOrderDao;
import edu.scau.mis.cloth.service.GsOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GsOrder)表服务实现类
 *
 * @author makejava
 * @since 2022-03-09 20:41:11
 */
@Service("gsOrderService")
public class GsOrderServiceImpl implements GsOrderService {

    @Resource
    private GsOrderDao gsOrderDao;


    @Override
    public List<Map<String,Object>> queryAll(){
        return this.gsOrderDao.queryAll();
    }

    @Override
    public Map<String,Object> queryOrderById(String id){return this.gsOrderDao.queryOrderById(id);}
    /**
     * 分页查询
     *
     * @param gsOrder 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsOrder> queryByPage(GsOrder gsOrder, PageRequest pageRequest) {
        long total = this.gsOrderDao.count(gsOrder);
        return new PageImpl<>(this.gsOrderDao.queryAllByLimit(gsOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param id 实例对象
     * @return 实例对象
     */
//
    @Override
    public int insert(String id) {
        return this.gsOrderDao.insert(id);
    }

    @Override
    public int queryTotalMoney(String id) {
        return this.gsOrderDao.queryTotalMoney(id);
    }

    @Override
    public int update(String id) {
        return gsOrderDao.update(id);
    }


    public int queryCount(String orderId){
        return gsOrderDao.queryCount(orderId);
    }

    /**
     * 通过主键删除数据
     *
     * @param
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String orderId) {
        return this.gsOrderDao.deleteById(orderId) > 0;
    }
}
